`
https://leetcode.cn/problems/mice-and-cheese/
`

/**
 * @param {number[]} reward1
 * @param {number[]} reward2
 * @param {number} k
 * @return {number}
 */
var miceAndCheese = function (reward1, reward2, k) {
  const n = reward1.length;
  // 先计算第二只老鼠吃所有奶酪的总分
  let total = reward2.reduce((sum, val) => sum + val, 0);

  // 计算每块奶酪如果由第一只老鼠吃的增益
  const gains = [];
  for (let i = 0; i < n; i++) {
    gains.push(reward1[i] - reward2[i]);
  }

  // 选择增益最大的k个
  gains.sort((a, b) => b - a);
  for (let i = 0; i < k; i++) {
    total += gains[i];
  }

  return total;
};